﻿/**************************************************************
 * Copyright www.eastmoney.com. All rights reserved.
 * 
 * Author: gt1987(guitao@eastmoney.com) 
 * Create Date: 2021/4/20 13:53:40
 * Description: 
 *          
 * Revision History:
 *      Date         Author               Description
 *              
***************************************************************/

using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace WorkerService.Sample
{
    public class LoopAsyncHostedService : BackgroundService
    {
        //必须执行过一遍 await  才不会堵塞
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await Task.Delay(2000, stoppingToken);
            while (!stoppingToken.IsCancellationRequested)
            {
                Console.WriteLine($"i am do loop work at times");
                //Task.Delay(2000, stoppingToken).GetAwaiter().GetResult();
                Thread.Sleep(2000);
            }
            await Task.Delay(2000, stoppingToken);
        }
    }
}
